home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 38 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.9 KB  |  57 lines

  1. Path: cs.umd.edu!not-for-mail
  2. From: torek@elf.bsdi.com (Chris Torek)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Undefined result vs. int's holding undefined values.
  5. Date: 5 Jan 1996 15:25:55 -0800
  6. Organization: Berkeley Software Design, Inc.
  7. Message-ID: <4ckc23$2ov@elf.bsdi.com>
  8. References: <4ck70b$rd7@news.informix.com>
  9. Reply-To: torek@bsdi.com
  10. NNTP-Posting-Host: elf.bsdi.com
  11.  
  12. In article <4ck70b$rd7@news.informix.com> Daniel Wood <dwood> wrote:
  13. >THE TEST CASE, on SCO:
  14.  
  15. (I think this means that INT_MIN is (-2147483647 - 1) and INT_MAX is
  16. 2147483647.)
  17.  
  18. >main() { f(-2147483647, 1879048192); }
  19. >
  20. >f(int x, int y) {
  21. >    int r;
  22. >
  23. >    if ((r=(x-y)) > 0)
  24. >        printf("1: r greater than 0\n");
  25. >
  26. >    if (r > 0)
  27. >        printf("2: r greater than 0\n");
  28. >}
  29. >
  30. >On SCO only the second print occurs.
  31.  
  32. I believe this is conformant.
  33.  
  34. Section 3.3, p. 39, ll. 15--18 (original ANSI numbering):
  35.  
  36.     If an /exception/ occurs during the evaluation of an expression
  37.     (that is, if the result is not mathematically defined or not in
  38.     the range of representable values for its type), the behavior is
  39.     undefined.
  40.  
  41. When undefined behavior occurs anywhere in any otherwise-conforming
  42. program, the behavior of the entire system becomes undefined.  A system
  43. that sometimes prints one, sometimes the other, sometimes neither,
  44. sometimes both, and sometimes prints insults, remains compliant.
  45.  
  46. >Saying a result is undefined "IS NOT EQUAL TO" saying that a C int variable
  47. >can actually hold an undefined value.  If you think the test case is running
  48. >acceptably, as described above, then tell me the section of the standard that
  49. >states or implies that an int variable can hold an undefined value.
  50.  
  51. See above.  Whether something can `hold an undefined value' is
  52. irrelevant; undefined *behavior* occurs on overflow, and that is
  53. all that matters to the Standard.
  54. -- 
  55. In-Real-Life: Chris Torek, Berkeley Software Design Inc
  56. El Cerrito, CA    Domain:    torek@bsdi.com    +1 510 234 3167
  57.